package Run_System;

import java.util.Random;

public abstract class Equation {
    protected int left_operand;    //左操作数
    protected int right_operand;   //算符
    protected char operator;       //右操作数
    protected int value;           //运算结果
    public static int MAX = 100;   //算式最大范围
    public static int MIN = 0;     //算式最小范围


    protected   abstract int caculate(int left,int right);//生成运算结果

    protected abstract boolean checkEquation(int left_operand,int right_operand); //检查算式是否在范围内

    protected abstract void constructor();//构造器

    protected int[] randomNum(int max,int min){   //生成MIN 到MAX之间的整数
        Random random = new Random();
        int [] arr = new int[2];
        arr[0] = (random.nextInt(max - min) + min+ 1);
        arr[1] = (random.nextInt(max - min) + min + 1);
        return arr;
    }


    public int getLeft_operand() {
        return left_operand;
    }

    public int getRight_operand() {
        return right_operand;
    }

    public char getOperator() {
        return operator;
    }

    public int getValue() {
        return value;
    }

    public static void setRange(int max,int min){    //设置算式范围
        MAX = max;
        MIN = min;
    }
    @Override
    public  String toString(){         //获取字符串
        return new String(left_operand+Character.toString(operator)+right_operand+"="+value);
    }


    public String toString(int i){return new String(left_operand+Character.toString(operator)+right_operand);}




    @Override
    public int hashCode() {
        return  (int)(left_operand % 13)+ Character.hashCode(operator) +(int)(right_operand % 13);
    }

    @Override
    public boolean equals(Object obj) {
        return  super.equals(obj);
    }//便于排重


}
